| Author | Manuela Ruiz (mruiz@lcc.uma.es) |
Utils class
Adds the default constraint and goals
# File lib/utils.rb, line 1288
1288: def ShadeUtils.add_cg_names()
1289: #Set list of constraint names and classes
1290: Shade.constraint_class_names = Array.new
1291: Shade.add_constraint_class_name [ DistinctShapeConstraint, Constants::DISTINCT_SHAPE_CONSTRAINT_NAME]
1292: Shade.add_constraint_class_name [ NoScalesConstraint, Constants::NO_SCALES_CONSTRAINT_NAME]
1293: Shade.add_constraint_class_name [ AreaConstraint, Constants::AREA_CONSTRAINT_NAME]
1294:
1295: #Set list of goals names and classes
1296: Shade.goal_class_names = Array.new
1297: Shade.add_goal_class_name([NoLabelsGoal, Constants::NO_LABELS_GOAL_NAME])
1298: Shade.add_goal_class_name([AllRulesAppliedGoal, Constants::ALL_RULES_APPLIED_GOAL_NAME])
1299: Shade.add_goal_class_name([NoMoreRulesGoal, Constants::NO_MORE_RULES_GOAL_NAME])
1300: end
Shows a dialog for saving the project
# File lib/utils.rb, line 420
420: def ShadeUtils.ask_to_save_project()
421: if Shade.using_sketchup
422: project = Shade.project
423: if !project.saved
424: input = UI.messagebox("Save current project?", MB_YESNO)
425: if input == 6
426: if project.path
427: project.save(project.path, true)
428: project.saved = true
429: else
430: path_to_save_to = UI.savepanel "Save Project", "", "project.prj"
431: if path_to_save_to
432: project.save(path_to_save_to, true)
433: end
434: project.saved = true
435: end
436: end
437:
438: end
439: end
440: end
| returns | the axiom |
# File lib/utils.rb, line 1179
1179: def ShadeUtils.axiom()
1180: return Shade.project.execution.grammar.axiom
1181: end
origin_rule_idx: index of the origin rule origin_rule_part: Constants::LEFT or Constants::RIGHT destiny_rule_idx: index of the destiny rule. If -1, we refer to the axiom (that is, the shape is going to be copied to the axiom) destiny_rule_part: “Left”, “Right”, “Additive” or “” in case we refer to the axiom
Copies the origin shape (the one in the specified part of the specified rule) to the specified destiny Maintains the old transformations
# File lib/utils.rb, line 755
755: def ShadeUtils.copy_shape(origin_rule_idx, origin_rule_part, destiny_rule_idx, destiny_rule_part)
756: execution = Shade.project.execution
757: origin_rule = execution.grammar.rules[origin_rule_idx]
758: destiny_rule = execution.grammar.rules[destiny_rule_idx]
759:
760: if origin_rule_part == Constants::LEFT
761: origin_shape = origin_rule.left
762: elsif origin_rule_part == Constants::RIGHT
763: origin_shape = origin_rule.right
764: end
765:
766: new_shape = origin_shape.clone
767: new_shape.host_rule_id = destiny_rule.rule_id
768: new_shape.host_rule_part = destiny_rule_part
769:
770: if Shade.using_sketchup
771: if destiny_rule_part == Constants::LEFT
772: Sketchup.active_model.layers.each { |layer|
773: shape_transformation = destiny_rule.alpha.shape_transformation[layer.name]
774: layout_transformation = destiny_rule.alpha.layout_transformation
775: destiny_rule.alpha.erase
776: destiny_rule.alpha = new_shape
777: destiny_rule.alpha.shape_transformation[layer.name]= shape_transformation
778: destiny_rule.alpha.layout_transformation = layout_transformation
779: }
780: elsif destiny_rule_part == Constants::RIGHT
781: Sketchup.active_model.layers.each { |layer|
782: shape_transformation = destiny_rule.beta.shape_transformation[layer.name]
783: layout_transformation = destiny_rule.beta.layout_transformation
784: destiny_rule.beta.erase
785: destiny_rule.beta = new_shape
786: destiny_rule.beta.shape_transformation[layer.name] = shape_transformation
787: destiny_rule.beta.layout_transformation = layout_transformation
788: }
789: end
790: else
791: if destiny_rule_part == Constants::LEFT
792: destiny_rule.alpha.erase
793: destiny_rule.alpha = new_shape
794: elsif destiny_rule_part == Constants::RIGHT
795: destiny_rule.beta.erase
796: destiny_rule.beta = new_shape
797: end
798: end
799:
800: execution.grammar.saved = false
801: end
| returns | a default axiom |
# File lib/utils.rb, line 443
443: def ShadeUtils.create_default_axiom()
444: axiom = LabelledShape.new(Array.new, Array.new)
445: segments = Array.new
446: segments[0] = Segment.new(OrderedPoint.new(Constants::PTS_1[0].clone), OrderedPoint.new(Constants::PTS_1[1].clone))
447: segments[1] = Segment.new(OrderedPoint.new(Constants::PTS_1[1].clone), OrderedPoint.new(Constants::PTS_1[2].clone))
448: segments[2] = Segment.new(OrderedPoint.new(Constants::PTS_1[2].clone), OrderedPoint.new(Constants::PTS_1[3].clone))
449: segments[3] = Segment.new(OrderedPoint.new(Constants::PTS_1[3].clone), OrderedPoint.new(Constants::PTS_1[0].clone))
450:
451: if Shade.using_sketchup
452: Sketchup.active_model.layers.each { |layer|
453: segments.each { |segment|
454: segment_list = LinearLinkedList.new
455:
456: node = LinearLinkedListNode.new(segment.line_descriptor.clone, segment_list, nil)
457:
458: inserted_node = axiom.s[layer.name].insert_node(node) #Insert the node corresponding to the line descriptor of the segment
459: segment_node = LinearLinkedListNode.new(segment.clone, nil, nil)
460: inserted_node.list.insert_node(segment_node)
461: }
462:
463: Constants::PTS_1.each {|point|
464: label = Label.new(Constants::INTERSECTION_LABEL)
465: point_list = LinearLinkedList.new
466:
467: node = LinearLinkedListNode.new(label, point_list, nil)
468:
469: inserted_node = axiom.p[layer.name].insert_node(node) #Insert the node corresponding to the label of the point
470:
471: point_node = LinearLinkedListNode.new(OrderedPoint.new(point.clone), nil, nil)
472: inserted_node.list.insert_node(point_node) #Insert the point node
473: }
474: }
475: else
476: segments.each { |segment|
477: segment_list = LinearLinkedList.new
478:
479: node = LinearLinkedListNode.new(segment.line_descriptor.clone, segment_list, nil)
480:
481: inserted_node = axiom.s["Layer0"].insert_node(node) #Insert the node corresponding to the line descriptor of the segment
482: segment_node = LinearLinkedListNode.new(segment.clone, nil, nil)
483: inserted_node.list.insert_node(segment_node)
484: }
485:
486: Constants::PTS_1.each {|point|
487: label = Label.new(Constants::INTERSECTION_LABEL)
488: point_list = LinearLinkedList.new
489:
490: node = LinearLinkedListNode.new(label, point_list, nil)
491:
492: inserted_node = axiom.p["Layer0"].insert_node(node) #Insert the node corresponding to the label of the point
493:
494: point_node = LinearLinkedListNode.new(OrderedPoint.new(point.clone), nil, nil)
495: inserted_node.list.insert_node(point_node) #Insert the point node
496: }
497: end
498: return axiom
499: end
| returns | a default current shape |
# File lib/utils.rb, line 503
503: def ShadeUtils.create_default_current_shape()
504: current_shape = CurrentLabelledShape.new(Array.new, Array.new)
505: segments = Array.new
506: segments[0] = Segment.new(OrderedPoint.new(Constants::PTS_1[0].clone), OrderedPoint.new(Constants::PTS_1[1].clone))
507: segments[1] = Segment.new(OrderedPoint.new(Constants::PTS_1[1].clone), OrderedPoint.new(Constants::PTS_1[2].clone))
508: segments[2] = Segment.new(OrderedPoint.new(Constants::PTS_1[2].clone), OrderedPoint.new(Constants::PTS_1[3].clone))
509: segments[3] = Segment.new(OrderedPoint.new(Constants::PTS_1[3].clone), OrderedPoint.new(Constants::PTS_1[0].clone))
510:
511: if Shade.using_sketchup
512: Sketchup.active_model.layers.each { |layer|
513: segments.each { |segment|
514: segment_list = LinearLinkedList.new
515:
516: node = BalancedBinaryTreeNode.new(0, nil, nil, segment.line_descriptor.clone, segment_list)
517:
518: inserted_node = current_shape.s[layer.name].insert_node(node) #Insert the node corresponding to the line descriptor of the segment
519: segment_node = LinearLinkedListNode.new(segment.clone, nil, nil)
520: inserted_node.list.insert_node(segment_node)
521: }
522:
523:
524: Constants::PTS_1.each {|point|
525: label = Label.new(Constants::INTERSECTION_LABEL)
526: point_list = LinearLinkedList.new
527:
528: node = LinearLinkedListNode.new(label, point_list, nil)
529:
530: inserted_node = current_shape.p[layer.name].insert_node(node) #Insert the node corresponding to the label of the point
531:
532: point_node = LinearLinkedListNode.new(OrderedPoint.new(point.clone), nil, nil)
533: inserted_node.list.insert_node(point_node) #Insert the point node
534: }
535: }
536: else
537: segments.each { |segment|
538: segment_list = LinearLinkedList.new
539:
540: node = BalancedBinaryTreeNode.new(0, nil, nil, segment.line_descriptor.clone, segment_list)
541:
542: inserted_node = current_shape.s["Layer0"].insert_node(node) #Insert the node corresponding to the line descriptor of the segment
543: segment_node = LinearLinkedListNode.new(segment.clone, nil, nil)
544: inserted_node.list.insert_node(segment_node)
545: }
546:
547:
548: Constants::PTS_1.each {|point|
549: label = Label.new(Constants::INTERSECTION_LABEL)
550: point_list = LinearLinkedList.new
551:
552: node = LinearLinkedListNode.new(label, point_list, nil)
553:
554: inserted_node = current_shape.p["Layer0"].insert_node(node) #Insert the node corresponding to the label of the point
555:
556: point_node = LinearLinkedListNode.new(OrderedPoint.new(point.clone), nil, nil)
557: inserted_node.list.insert_node(point_node) #Insert the point node
558: }
559: end
560: current_shape.create_pi
561: return current_shape
562: end
| returns | a default left shape for the rules |
# File lib/utils.rb, line 565
565: def ShadeUtils.create_default_left_shape()
566: shape = RuleLabelledShape.new(Array.new, Array.new, nil, nil)
567: segments = Array.new
568: segments[0] = Segment.new(OrderedPoint.new(Constants::PTS_1[0].clone), OrderedPoint.new(Constants::PTS_1[1].clone))
569: segments[1] = Segment.new(OrderedPoint.new(Constants::PTS_1[1].clone), OrderedPoint.new(Constants::PTS_1[2].clone))
570: segments[2] = Segment.new(OrderedPoint.new(Constants::PTS_1[2].clone), OrderedPoint.new(Constants::PTS_1[3].clone))
571: segments[3] = Segment.new(OrderedPoint.new(Constants::PTS_1[3].clone), OrderedPoint.new(Constants::PTS_1[0].clone))
572:
573: if Shade.using_sketchup
574: Sketchup.active_model.layers.each { |layer|
575: segments.each { |segment|
576: segment_list = LinearLinkedList.new
577:
578: node = LinearLinkedListNode.new(segment.line_descriptor.clone, segment_list, nil)
579:
580: inserted_node = shape.s[layer.name].insert_node(node) #Insert the node corresponding to the line descriptor of the segment
581: segment_node = LinearLinkedListNode.new(segment.clone, nil, nil)
582: inserted_node.list.insert_node(segment_node)
583: }
584:
585: Constants::PTS_1.each {|point|
586: label = Label.new(Constants::INTERSECTION_LABEL)
587: point_list = LinearLinkedList.new
588:
589: node = LinearLinkedListNode.new(label, point_list, nil)
590:
591: inserted_node = shape.p[layer.name].insert_node(node) #Insert the node corresponding to the label of the point
592:
593: point_node = LinearLinkedListNode.new(OrderedPoint.new(point.clone), nil, nil)
594: inserted_node.list.insert_node(point_node) #Insert the point node
595: }
596: }
597: shape.changed = true
598: else
599: segments.each { |segment|
600: segment_list = LinearLinkedList.new
601:
602: node = LinearLinkedListNode.new(segment.line_descriptor.clone, segment_list, nil)
603:
604: inserted_node = shape.s["Layer0"].insert_node(node) #Insert the node corresponding to the line descriptor of the segment
605: segment_node = LinearLinkedListNode.new(segment.clone, nil, nil)
606: inserted_node.list.insert_node(segment_node)
607: }
608:
609: Constants::PTS_1.each {|point|
610: label = Label.new(Constants::INTERSECTION_LABEL)
611: point_list = LinearLinkedList.new
612:
613: node = LinearLinkedListNode.new(label, point_list, nil)
614:
615: inserted_node = shape.p["Layer0"].insert_node(node) #Insert the node corresponding to the label of the point
616:
617: point_node = LinearLinkedListNode.new(OrderedPoint.new(point.clone), nil, nil)
618: inserted_node.list.insert_node(point_node) #Insert the point node
619: }
620: end
621: return shape
622: end
Creates and loads a default grammar
# File lib/utils.rb, line 805
805: def ShadeUtils.create_default_new_grammar
806: execution = Shade.project.execution
807: rules = execution.grammar.rules
808:
809: size = rules.size
810: i = 0
811: while i < size
812: execution.grammar.remove_rule(size-i-1)
813: i += 1
814: end
815:
816: # Create default shapes for the first rule
817: left = ShadeUtils.create_default_left_shape()
818: right = ShadeUtils.create_default_right_shape()
819:
820: # Create the first rule
821: rule = ShadeUtils.paint_rule(1, left, right)
822: execution.grammar.add_rule(rule)
823: execution.grammar.saved = true
824:
825: #Create the axiom
826: execution.grammar.axiom = create_default_axiom
827: execution.reset
828:
829: Shade.project.refresh
830: end
Creates and loads a new project
# File lib/utils.rb, line 835
835: def ShadeUtils.create_default_new_project()
836: project = Shade.project
837: project.set_title(Constants::DEFAULT_PROJECT_TITLE)
838:
839: project.set_path(nil)
840:
841: ShadeUtils.create_default_new_grammar()
842:
843: project.execution.constraints = Array.new
844: project.execution.goals = Array.new
845:
846: project.refresh
847:
848: project.saved = true
849: end
| returns | a default project |
# File lib/utils.rb, line 852
852: def ShadeUtils.create_default_project
853:
854: # Create the grammar
855: grammar = Grammar.new
856:
857: # Create the execution
858: execution = Execution.new(grammar, nil)
859:
860: # Create the project
861: project = Project.new(execution)
862:
863: #Add the project to Shade
864: Shade.project = project
865:
866: #Create default shapes for the first rule
867: left = ShadeUtils.create_default_left_shape()
868: right = ShadeUtils.create_default_right_shape()
869:
870: #Create the axiom
871: execution.grammar.axiom = create_default_axiom
872: execution.current_shape = create_default_current_shape
873:
874: # Create the first rule
875: rule = ShadeUtils.paint_rule(1, left, right)
876:
877:
878: # Add rule to the grammar
879: grammar.add_rule rule
880:
881: grammar.saved = true
882:
883: # Associate the grammar with the execution
884: execution.grammar = grammar
885:
886: if Shade.using_sketchup
887: # We only need to do this once. Then, only changing observed ids is needed
888: Shade.rule_groups_observer = RuleGroupsObserver.new
889: Sketchup.active_model.entities.add_observer(Shade.rule_groups_observer)
890: end
891:
892: # Return the project
893: return project
894: end
| returns | a default right shape for the rules |
# File lib/utils.rb, line 625
625: def ShadeUtils.create_default_right_shape()
626: shape = RuleLabelledShape.new(Array.new, Array.new, nil, nil)
627: segments = Array.new
628: segments[0] = Segment.new(OrderedPoint.new(Constants::PTS_1[0].clone), OrderedPoint.new(Constants::PTS_1[1].clone))
629: segments[1] = Segment.new(OrderedPoint.new(Constants::PTS_1[1].clone), OrderedPoint.new(Constants::PTS_1[2].clone))
630: segments[2] = Segment.new(OrderedPoint.new(Constants::PTS_1[2].clone), OrderedPoint.new(Constants::PTS_1[3].clone))
631: segments[3] = Segment.new(OrderedPoint.new(Constants::PTS_1[3].clone), OrderedPoint.new(Constants::PTS_1[0].clone))
632:
633: segments[4] = Segment.new(OrderedPoint.new(Constants::PTS_2[0].clone), OrderedPoint.new(Constants::PTS_2[1].clone))
634: segments[5] = Segment.new(OrderedPoint.new(Constants::PTS_2[1].clone), OrderedPoint.new(Constants::PTS_2[2].clone))
635: segments[6] = Segment.new(OrderedPoint.new(Constants::PTS_2[2].clone), OrderedPoint.new(Constants::PTS_2[3].clone))
636: segments[7] = Segment.new(OrderedPoint.new(Constants::PTS_2[3].clone), OrderedPoint.new(Constants::PTS_2[0].clone))
637:
638: if Shade.using_sketchup
639: Sketchup.active_model.layers.each { |layer|
640: segments.each { |segment|
641: segment_list = LinearLinkedList.new
642:
643: node = LinearLinkedListNode.new(segment.line_descriptor.clone, segment_list, nil)
644:
645: inserted_node = shape.s[layer.name].insert_node(node) #Insert the node corresponding to the line descriptor of the segment
646: segment_node = LinearLinkedListNode.new(segment.clone, nil, nil)
647: inserted_node.list.insert_node(segment_node)
648: }
649:
650: Constants::PTS_1.each {|point|
651: label = Label.new(Constants::INTERSECTION_LABEL)
652: point_list = LinearLinkedList.new
653:
654: node = LinearLinkedListNode.new(label, point_list, nil)
655:
656: inserted_node = shape.p[layer.name].insert_node(node) #Insert the node corresponding to the label of the point
657:
658: point_node = LinearLinkedListNode.new(OrderedPoint.new(point.clone), nil, nil)
659: inserted_node.list.insert_node(point_node) #Insert the point node
660: }
661:
662: Constants::PTS_2.each {|point|
663: label = Label.new(Constants::INTERSECTION_LABEL)
664: point_list = LinearLinkedList.new
665:
666: node = LinearLinkedListNode.new(label, point_list, nil)
667:
668: inserted_node = shape.p[layer.name].insert_node(node) #Insert the node corresponding to the label of the point
669:
670: point_node = LinearLinkedListNode.new(OrderedPoint.new(point.clone), nil, nil)
671: inserted_node.list.insert_node(point_node) #Insert the point node
672: }
673:
674: label = Label.new(Constants::INTERSECTION_LABEL)
675: intersection_label_node = shape.p[layer.name].get_node(label)
676:
677: #Insert the other intersection points
678: point_node1 = LinearLinkedListNode.new(OrderedPoint.new(Geom::Point3d.new(4,8,0)), nil, nil)
679: point_node2 = LinearLinkedListNode.new(OrderedPoint.new(Geom::Point3d.new(8,4,0)), nil, nil)
680: intersection_label_node.list.insert_node(point_node1) #Insert the point node
681: intersection_label_node.list.insert_node(point_node2) #Insert the point node
682: }
683:
684: shape.changed = true
685: else
686: segments.each { |segment|
687: segment_list = LinearLinkedList.new
688:
689: node = LinearLinkedListNode.new(segment.line_descriptor.clone, segment_list, nil)
690:
691: inserted_node = shape.s["Layer0"].insert_node(node) #Insert the node corresponding to the line descriptor of the segment
692: segment_node = LinearLinkedListNode.new(segment.clone, nil, nil)
693: inserted_node.list.insert_node(segment_node)
694: }
695:
696: Constants::PTS_1.each {|point|
697: label = Label.new(Constants::INTERSECTION_LABEL)
698: point_list = LinearLinkedList.new
699:
700: node = LinearLinkedListNode.new(label, point_list, nil)
701:
702: inserted_node = shape.p["Layer0"].insert_node(node) #Insert the node corresponding to the label of the point
703:
704: point_node = LinearLinkedListNode.new(OrderedPoint.new(point.clone), nil, nil)
705: inserted_node.list.insert_node(point_node) #Insert the point node
706: }
707:
708: Constants::PTS_2.each {|point|
709: label = Label.new(Constants::INTERSECTION_LABEL)
710: point_list = LinearLinkedList.new
711:
712: node = LinearLinkedListNode.new(label, point_list, nil)
713:
714: inserted_node = shape.p["Layer0"].insert_node(node) #Insert the node corresponding to the label of the point
715:
716: point_node = LinearLinkedListNode.new(OrderedPoint.new(point.clone), nil, nil)
717: inserted_node.list.insert_node(point_node) #Insert the point node
718: }
719:
720: label = Label.new(Constants::INTERSECTION_LABEL)
721: intersection_label_node = shape.p["Layer0"].get_node(label)
722:
723: #Insert the other intersection points
724: point_node1 = LinearLinkedListNode.new(OrderedPoint.new(Point.new(4,8,0)), nil, nil)
725: point_node2 = LinearLinkedListNode.new(OrderedPoint.new(Point.new(8,4,0)), nil, nil)
726: intersection_label_node.list.insert_node(point_node1) #Insert the point node
727: intersection_label_node.list.insert_node(point_node2) #Insert the point node
728: end
729: return shape
730: end
returns: a String object with a list of the present rule IDs, for example, if there are four rules: “1|2|3|4”
# File lib/utils.rb, line 734
734: def ShadeUtils.create_rule_list()
735: execution = Shade.project.execution
736: rule_list = ""
737: rules_size = execution.grammar.rules.size
738: rules_size.times do |s|
739: if (s+1) == rules_size
740: rule_list = "#{rule_list}#{s+1}"
741: else
742: rule_list = "#{rule_list}#{s+1}|"
743: end
744: end
745: return rule_list
746: end
| returns | the current shape |
# File lib/utils.rb, line 1165
1165: def ShadeUtils.current_shape()
1166: return Shade.project.execution.current_shape
1167: end
| returns | the id of the first rule applied |
# File lib/utils.rb, line 1246
1246: def ShadeUtils.first_rule_id()
1247: if Shade.project.execution.execution_history
1248: return Shade.project.execution.execution_history.first[0]
1249: else
1250: return nil
1251: end
1252: end
| path | a String representing a path of a file inside the system |
| returns | the parent directory of the file represented by the path |
# File lib/utils.rb, line 1151
1151: def ShadeUtils.get_directory_from_path(path)
1152: i = path.rindex("\\")
1153: return path[0..i]
1154: end
| path | a String representing a path of a file inside the system, returned by the SketchUp utils for getting paths |
| returns | the parent directory of the file represented by the path |
# File lib/utils.rb, line 1159
1159: def ShadeUtils.get_directory_from_sketchup_path(path)
1160: i = path.rindex("/")
1161: return path[0..i]
1162: end
| returns | the current execution |
# File lib/utils.rb, line 1222
1222: def ShadeUtils.get_execution()
1223: return Shade.project.execution
1224: end
| path | a String representing a path of a file inside the system |
| returns | the extension of the file represented by the path |
# File lib/utils.rb, line 1138
1138: def ShadeUtils.get_extension(path)
1139: if path.rindex(".")
1140: i = path.rindex(".") + 1
1141: j = (path.length) -1
1142: return path[i..j]
1143: else
1144: return nil
1145: end
1146: end
| returns | the current grammar |
# File lib/utils.rb, line 1232
1232: def ShadeUtils.get_grammar()
1233: return Shade.project.execution.grammar
1234: end
| shape | a LabelledShape object |
| type | String that can take the values “ALL” (referring to all types of labels) or “INTERSECTION” (referring only to the intersection points) |
| returns | an Array with the lists of labels present in the current shape |
# File lib/utils.rb, line 1187
1187: def ShadeUtils.get_labels(shape, type)
1188:
1189: labels = Array.new
1190: case type
1191: when ("ALL" or "All")
1192: shape.p.each_key { |layer_name|
1193: ShadeUtils.current_shape.p[layer_name].reset_iterator
1194: while l_node = ShadeUtils.current_shape.p[layer_name].get_next
1195: labels.push l_node.list
1196: end
1197: }
1198: when ("INTERSECTION" or "Intersection")
1199:
1200: shape.p.each_key { |layer_name|
1201:
1202: l_node = ShadeUtils.current_shape.p[layer_name].get_node(Label.new(Constants::INTERSECTION_LABEL))
1203: if l_node
1204: labels.push l_node.list
1205: end
1206: }
1207: else
1208: shape.p.each_key { |layer_name|
1209: l_node = ShadeUtils.current_shape.p[layer_name].get_node(Label.new(type.capitalize))
1210: if l_node
1211: labels.push l_node.list
1212: end
1213: }
1214:
1215:
1216: end
1217:
1218: return labels
1219: end
| returns | the current project |
# File lib/utils.rb, line 1227
1227: def ShadeUtils.get_project()
1228: return Shade.project
1229: end
| rule_idx | an integer number |
| returns | the rule with the specified index, that is, that is in the rule_idx position of the array of rules |
# File lib/utils.rb, line 1279
1279: def ShadeUtils.get_rule(rule_idx)
1280: if rule_idx > Shade.project.execution.grammar.rules.size
1281: puts "Index out of range"
1282: else
1283: return Shade.project.execution.grammar.rules[rule_idx]
1284: end
1285: end
| path | a String representing a path of a file inside the system |
| returns | the title of the file represented by the path |
# File lib/utils.rb, line 1120
1120: def ShadeUtils.get_title_from_path(path)
1121: i = path.rindex("\\")+1
1122: j = path.rindex(".")-1
1123: return path[i..j]
1124: end
| path | a String representing a path of a file inside the system, returned by the SketchUp utils for getting paths |
| returns | the title of the file represented by the path |
# File lib/utils.rb, line 1129
1129: def ShadeUtils.get_title_from_sketchup_path(path)
1130: i = path.rindex("/")+1
1131: j = path.rindex(".")-1
1132: return path[i..j]
1133: end
| point | a Point object |
| segment | a Segment object |
| returns | the distance, in meters, from point to segment (ortogonally projected) |
# File lib/utils.rb, line 410
410: def ShadeUtils.is_projected?(point, segment)
411: result = false
412: projected_point = OrderedPoint.new(point.project_to_line(segment.line_descriptor, segment.tail, segment.head))
413: if segment.coincident? projected_point
414: result = true
415: end
416: return result
417: end
| returns | the id of the last rule applied |
# File lib/utils.rb, line 1237
1237: def ShadeUtils.last_rule_id()
1238: if Shade.project.execution.execution_history
1239: return Shade.project.execution.execution_history.last[0]
1240: else
1241: return nil
1242: end
1243: end
| returns | the transformation of the last rule applied |
# File lib/utils.rb, line 1268
1268: def ShadeUtils.last_rule_transformation()
1269: if Shade.project.execution.execution_history
1270: return Shade.project.execution.execution_history.last[1]
1271: else
1272: return nil
1273: end
1274: end
Loads the constraints present in the directory “custom_constraints“
# File lib/utils.rb, line 273
273: def ShadeUtils.load_custom_constraints()
274: #We suppose that custom constraints have already been syntax-checked and executed
275: if Shade.using_sketchup
276: file_name = Sketchup.find_support_file Constants::STARTUP_FILE_NAME, Constants::LIB_DIR
277: directory = ShadeUtils.get_directory_from_sketchup_path(file_name)
278: custom_constraints_directory = "#{directory}/#{Constants::CONSTRAINT_FOLDER_NAME}"
279: else
280: custom_constraints_directory = "#{File.dirname(__FILE__)}/#{Constants::CONSTRAINT_FOLDER_NAME}"
281: custom_constraints_directory.gsub!("/", "\\")
282: end
283: old_dir = Dir.pwd
284: Dir.chdir(custom_constraints_directory)
285:
286: #For each file inside the custom constraints directory
287: Dir.entries(".").each { |file_name|
288: if Shade.using_sketchup
289: file_path = "#{custom_constraints_directory}/#{file_name}"
290: name = get_title_from_sketchup_path(file_path)
291: else
292: file_path = "#{custom_constraints_directory}\\#{file_name}"
293: name = get_title_from_path(file_path)
294: end
295: extension = get_extension(file_path)
296: if extension == "txt"
297: code = ""
298: File.open(file_path, 'r') do |f|
299: while line = f.gets
300: code += line
301: end
302: end
303:
304: #Make the right class
305: class_name = name.gsub(" ", "_")
306: Object.const_set(class_name, Class.new {
307:
308: eval("attr_reader :name")
309:
310: eval("def initialize; @name = \"#{name}\" end")
311:
312: eval("def satisfied?; result = true\n #{code} \n end")
313:
314: eval("def delete; end")
315:
316: })
317:
318: #Add the class and the name to the Shade.constraint_class_names
319: constraint_class = eval("#{class_name}")
320: Shade.add_constraint_class_name([constraint_class, name])
321: end
322: }
323:
324: Dir.chdir(old_dir)
325: end
Loads the goals present in the directory “custom_constraints“
# File lib/utils.rb, line 329
329: def ShadeUtils.load_custom_goals()
330: #We suppose that custom constraints have already been syntax-checked and executed
331: if Shade.using_sketchup
332: file_name = Sketchup.find_support_file Constants::STARTUP_FILE_NAME, Constants::LIB_DIR
333: directory = ShadeUtils.get_directory_from_sketchup_path(file_name)
334: custom_goals_directory = "#{directory}/#{Constants::GOAL_FOLDER_NAME}"
335: else
336: custom_goals_directory = "#{File.dirname(__FILE__)}/#{Constants::GOAL_FOLDER_NAME}"
337: custom_goals_directory.gsub!("/", "\\")
338: end
339:
340: old_dir = Dir.pwd
341: Dir.chdir(custom_goals_directory)
342:
343: #For each file inside the custom constraints directory
344: Dir.entries(".").each { |file_name|
345: if Shade.using_sketchup
346: file_path = "#{custom_goals_directory}/#{file_name}"
347: name = get_title_from_sketchup_path(file_path)
348: else
349: file_path = "#{custom_goals_directory}\\#{file_name}"
350: name = get_title_from_path(file_path)
351: end
352: extension = get_extension(file_path)
353: if extension == "txt"
354: code = ""
355: File.open(file_path, 'r') do |f|
356: while line = f.gets
357: code += line
358: end
359: end
360:
361: #Make the right class
362: class_name = name.gsub(" ", "_")
363: Object.const_set(class_name, Class.new {
364:
365: eval("attr_reader :name")
366:
367: eval("def initialize; @name = \"#{name}\" end")
368:
369: eval("def satisfied?; result = true\n #{code} \n end")
370:
371: eval("def delete; end")
372:
373: })
374:
375: #Add the class and the name to the Shade.constraint_class_names
376: goal_class = eval("#{class_name}")
377: Shade.add_goal_class_name([goal_class, name])
378: end
379: }
380:
381: Dir.chdir(old_dir)
382: end
Adds observers, descends the shapes and paint lines and arrow
# File lib/utils.rb, line 981
981: def ShadeUtils.paint_rule(id, left, right)
982:
983: execution = Shade.project.execution
984:
985: previous_rule = execution.grammar.search_rule_by_id(id)
986:
987: if previous_rule
988: UI.messagebox("The id #{id} is already in use")
989: return nil
990: end
991:
992: if Shade.using_sketchup
993:
994: # Get handles
995: entities = Sketchup.active_model.entities
996:
997: if execution.grammar
998: idx = execution.grammar.rules.size
999: else
1000: idx = 0
1001: end
1002: t = idx
1003:
1004: # Transform the layout transformation of the shapes
1005: t_left = Geom::Transformation.new
1006: t_right = Geom::Transformation.new
1007: t.times do
1008: t_left = Constants::DESCEND_T * t_left
1009: t_right = Constants::DESCEND_T * t_right
1010: end
1011: t_left = Constants::LEFT_T * t_left
1012: t_right = Constants::RIGHT_T * t_right
1013: left.layout_transformation = t_left
1014: right.layout_transformation = t_right
1015:
1016: group_arrow = Hash.new(nil)
1017: Sketchup.active_model.layers.each { |layer|
1018: # Draw an arrow, for the rule
1019: point1 = Constants::PTS_ARROW[0].clone
1020: point2 = Constants::PTS_ARROW[1].clone
1021: point3 = Constants::PTS_ARROW[2].clone
1022: point4 = Constants::PTS_ARROW[3].clone
1023:
1024: t.times do
1025: point1.transform! Constants::DESCEND_T
1026: point2.transform! Constants::DESCEND_T
1027: point3.transform! Constants::DESCEND_T
1028: point4.transform! Constants::DESCEND_T
1029: end
1030:
1031: group_arrow[layer.name] = entities.add_group
1032: group_arrow[layer.name].entities.add_line point1, point2
1033: group_arrow[layer.name].entities.add_line point3, point2
1034: group_arrow[layer.name].entities.add_line point4, point2
1035: group_arrow[layer.name].layer = layer
1036: group_arrow[layer.name].locked = true
1037: }
1038:
1039: group_origin_right = Hash.new(nil)
1040: group_origin_left = Hash.new(nil)
1041: Sketchup.active_model.layers.each { |layer|
1042: #Draw the origin references
1043: point1 = Constants::PTS_ORIGIN[0].clone
1044: point2 = Constants::PTS_ORIGIN[1].clone
1045: point3 = Constants::PTS_ORIGIN[2].clone
1046: point4 = Constants::PTS_ORIGIN[3].clone
1047:
1048: group_origin_left[layer.name] = entities.add_group
1049: group_origin_left[layer.name].entities.add_edges point1, point3
1050: group_origin_left[layer.name].entities.add_edges point2, point4
1051: group_origin_left[layer.name].transformation = t_left
1052: group_origin_left[layer.name].layer = layer
1053: group_origin_left[layer.name].locked = true
1054:
1055:
1056: group_origin_right[layer.name] = entities.add_group
1057: group_origin_right[layer.name].entities.add_edges point1, point3
1058: group_origin_right[layer.name].entities.add_edges point2, point4
1059: group_origin_right[layer.name].transformation = t_right
1060: group_origin_right[layer.name].layer = layer
1061: group_origin_right[layer.name].locked = true
1062:
1063: }
1064:
1065: line_group = Hash.new(nil)
1066: Sketchup.active_model.layers.each { |layer|
1067: #Draw horizontal line
1068: point_h1 = Constants::PTS_H[0].clone
1069: point_h2 = Constants::PTS_H[1].clone
1070:
1071: t.times do
1072: point_h1.transform! Constants::DESCEND_T
1073: point_h2.transform! Constants::DESCEND_T
1074: end
1075: line_group[layer.name] = entities.add_group
1076: line_group[layer.name].entities.add_line point_h1,point_h2
1077: line_group[layer.name].layer = layer
1078: line_group[layer.name].locked = true
1079:
1080: }
1081: end
1082:
1083: # Create the rule
1084: rule = Rule.new(id, left, right, line_group, group_arrow, group_origin_left, group_origin_right)
1085:
1086: return rule
1087: end
| rule_idx | the index of a rule |
| layer_name | a name of a layer |
Paints the given layer of the rule specified by rule_idx
# File lib/utils.rb, line 901
901: def ShadeUtils.paint_rule_layout(rule_idx, layer_name)
902:
903: if Shade.using_sketchup
904: execution = Shade.project.execution
905: rule = execution.grammar.rules[rule_idx]
906:
907: entities = Sketchup.active_model.entities
908:
909: t = rule_idx
910:
911: Sketchup.active_model.layers.each { |layer|
912: if layer.name == layer_name
913: # Draw an arrow, for the rule
914: point1 = Constants::PTS_ARROW[0].clone
915: point2 = Constants::PTS_ARROW[1].clone
916: point3 = Constants::PTS_ARROW[2].clone
917: point4 = Constants::PTS_ARROW[3].clone
918:
919: t.times do
920: point1.transform! Constants::DESCEND_T
921: point2.transform! Constants::DESCEND_T
922: point3.transform! Constants::DESCEND_T
923: point4.transform! Constants::DESCEND_T
924: end
925:
926: rule.arrow_group[layer.name] = entities.add_group
927: rule.arrow_group[layer.name].entities.add_line point1, point2
928: rule.arrow_group[layer.name].entities.add_line point3, point2
929: rule.arrow_group[layer.name].entities.add_line point4, point2
930: rule.arrow_group[layer.name].layer = layer
931: rule.arrow_group[layer.name].locked = true
932: end
933: }
934:
935: Sketchup.active_model.layers.each { |layer|
936: if layer.name == layer_name
937: #Draw the origin references
938: point1 = Constants::PTS_ORIGIN[0].clone
939: point2 = Constants::PTS_ORIGIN[1].clone
940: point3 = Constants::PTS_ORIGIN[2].clone
941: point4 = Constants::PTS_ORIGIN[3].clone
942:
943: rule.group_origin_left[layer.name] = entities.add_group
944: rule.group_origin_left[layer.name].entities.add_edges point1, point3
945: rule.group_origin_left[layer.name].entities.add_edges point2, point4
946: rule.group_origin_left[layer.name].transformation = rule.left.layout_transformation
947: rule.group_origin_left[layer.name].layer = layer
948: rule.group_origin_left[layer.name].locked = true
949:
950:
951: rule.group_origin_right[layer.name] = entities.add_group
952: rule.group_origin_right[layer.name].entities.add_edges point1, point3
953: rule.group_origin_right[layer.name].entities.add_edges point2, point4
954: rule.group_origin_right[layer.name].transformation = rule.right.layout_transformation
955: rule.group_origin_right[layer.name].layer = layer
956: rule.group_origin_right[layer.name].locked = true
957: end
958: }
959:
960: Sketchup.active_model.layers.each { |layer|
961: if layer.name == layer_name
962: #Draw horizontal line
963: point_h1 = Constants::PTS_H[0].clone
964: point_h2 = Constants::PTS_H[1].clone
965:
966: t.times do
967: point_h1.transform! Constants::DESCEND_T
968: point_h2.transform! Constants::DESCEND_T
969: end
970: rule.line_group[layer.name] = entities.add_group
971: rule.line_group[layer.name].entities.add_line point_h1,point_h2
972: rule.line_group[layer.name].layer = layer
973: rule.line_group[layer.name].locked = true
974: end
975: }
976: end
977: end
| point | a Point object |
| segment | a Segment object |
| returns | the distance, in meters, from point to segment (ortogonally projected) |
# File lib/utils.rb, line 391
391: def ShadeUtils.point_segment_distance(point, segment)
392: projected_point = OrderedPoint.new(point.project_to_line(segment.line_descriptor, segment.tail, segment.head))
393: if segment.coincident? projected_point
394: distance = point.distance(projected_point.point)
395: else
396: distance_start = point.distance(segment.tail.point)
397: distance_end = point.distance(segment.head.point)
398: distance = distance_end
399: if distance_start < distance_end
400: distance = distance_start
401: end
402: end
403: return distance
404: end
| axes | true iff the axes are to be shown |
Prepares the canvas for the plugin
# File lib/utils.rb, line 1094
1094: def ShadeUtils.prepare_canvas(axes = true)
1095: if Shade.using_sketchup
1096: # Prepare view
1097: Sketchup.send_action("viewTop:")
1098: if axes
1099: Sketchup.send_action("viewShowAxes:")
1100: end
1101:
1102: # Center view
1103: eye = [Constants::PTS_H[1][0], Constants::PTS_H[1][1], Constants::INITIAL_Z_CAMERA]
1104: target = Constants::PTS_H[1]
1105: up = Sketchup.active_model.active_view.camera.up
1106: Sketchup.active_model.active_view.camera.set eye, target, up
1107:
1108: # Draw vertical line
1109: point1 = Constants::PTS_V[0].clone
1110: point2 = Constants::PTS_V[1].clone
1111: group = Sketchup.active_model.entities.add_group
1112: group.entities.add_line point1,point2
1113: end
1114: end
| returns | the id of the rule applied previously to the last one |
# File lib/utils.rb, line 1255
1255: def ShadeUtils.previous_rule_id()
1256: if Shade.project.execution.execution_history
1257: if Shade.project.execution.execution_history.size > 1
1258: return Shade.project.execution.execution_history[Shade.project.execution.execution_history.size - 2][0]
1259: else
1260: return nil
1261: end
1262: else
1263: return nil
1264: end
1265: end
| returns | the shape previous to the last rule application |
# File lib/utils.rb, line 1170
1170: def ShadeUtils.previous_shape()
1171: if Shade.project.execution.execution_history
1172: return Shade.project.execution.execution_history.last[2]
1173: else
1174: return nil
1175: end
1176: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.